<!DOCTYPE html>

<html>
<head>
<meta charset="UTF-8">

<title>class AboutYou::SDK::Model::BasketSet - RDoc Documentation</title>

<link href="../../../fonts.css" rel="stylesheet">
<link href="../../../rdoc.css" rel="stylesheet">

<script type="text/javascript">
  var rdoc_rel_prefix = "../../../";
</script>

<script src="../../../js/jquery.js"></script>
<script src="../../../js/navigation.js"></script>
<script src="../../../js/search_index.js"></script>
<script src="../../../js/search.js"></script>
<script src="../../../js/searcher.js"></script>
<script src="../../../js/darkfish.js"></script>


<body id="top" role="document" class="class">
<nav role="navigation">
  <div id="project-navigation">
    <div id="home-section" role="region" title="Quick navigation" class="nav-section">
  <h2>
    <a href="../../../index.html" rel="home">Home</a>
  </h2>

  <div id="table-of-contents-navigation">
    <a href="../../../table_of_contents.html#pages">Pages</a>
    <a href="../../../table_of_contents.html#classes">Classes</a>
    <a href="../../../table_of_contents.html#methods">Methods</a>
  </div>
</div>

    <div id="search-section" role="search" class="project-section initially-hidden">
  <form action="#" method="get" accept-charset="utf-8">
    <div id="search-field-wrapper">
      <input id="search-field" role="combobox" aria-label="Search"
             aria-autocomplete="list" aria-controls="search-results"
             type="text" name="search" placeholder="Search" spellcheck="false"
             title="Type to search, Up and Down to navigate, Enter to load">
    </div>

    <ul id="search-results" aria-label="Search Results"
        aria-busy="false" aria-expanded="false"
        aria-atomic="false" class="initially-hidden"></ul>
  </form>
</div>

  </div>

  

  <div id="class-metadata">
    
    <div id="parent-class-section" class="nav-section">
  <h3>Parent</h3>

  
  <p class="link">Object
  
</div>

    <div id="includes-section" class="nav-section">
  <h3>Included Modules</h3>

  <ul class="link-list">
  
  
    <li><a class="include" href="ResultError.html">AboutYou::SDK::Model::ResultError</a>
  
  
  
    <li><a class="include" href="AbstractBasketItem.html">AboutYou::SDK::Model::AbstractBasketItem</a>
  
  
  </ul>
</div>

    
    <!-- Method Quickref -->
<div id="method-list-section" class="nav-section">
  <h3>Methods</h3>

  <ul class="link-list" role="directory">
    
    <li ><a href="#method-c-new">::new</a>
    
    <li ><a href="#method-i-add_item">#add_item</a>
    
    <li ><a href="#method-i-check_id">#check_id</a>
    
    <li ><a href="#method-i-create">#create</a>
    
    <li ><a href="#method-i-create_from_json">#create_from_json</a>
    
    <li ><a href="#method-i-errors-3F">#errors?</a>
    
    <li ><a href="#method-i-unique_key">#unique_key</a>
    
  </ul>
</div>

  </div>
</nav>

<main role="main" aria-labelledby="class-AboutYou::SDK::Model::BasketSet">
  <h1 id="class-AboutYou::SDK::Model::BasketSet" class="class">
    class AboutYou::SDK::Model::BasketSet
  </h1>

  <section class="description">
    
<p><a href="BasketSet.html">BasketSet</a> is a class used for adding a set of
variant items into the basket</p>

<p>If you want to add a set of variant items into a basket, you need to create
an instance of a <a href="BasketSet.html">BasketSet</a>. The <a
href="BasketSet.html">BasketSet</a> contains BasketSetItems.</p>

<p>A set can be useful if you want to sell several variants as a single
product. For example, if you offer a pair of shoes and additionally
different styles of shoelaces the customer can choose from, you maybe want
to put both - shoes and laces - together.</p>

  </section>

  
  
  
  <section id="5Buntitled-5D" class="documentation-section">
    

    

    
    <section class="constants-list">
      <header>
        <h3>Constants</h3>
      </header>
      <dl>
      
        <dt id="IMAGE_URL_REQUIRED">IMAGE_URL_REQUIRED
        
        <dd><p>determines if an image url is required</p>
        
      
      </dl>
    </section>
    

    
    <section class="attribute-method-details" class="method-section">
      <header>
        <h3>Attributes</h3>
      </header>

      
      <div id="attribute-i-errors" class="method-detail">
        <div class="method-heading attribute-method-heading">
          <span class="method-name">errors</span><span
            class="attribute-access-type">[RW]</span>
        </div>

        <div class="method-description">
        
        <p>array containing errors</p>
        
        </div>
      </div>
      
      <div id="attribute-i-id" class="method-detail">
        <div class="method-heading attribute-method-heading">
          <span class="method-name">id</span><span
            class="attribute-access-type">[RW]</span>
        </div>

        <div class="method-description">
        
        <p>The ID of this basket item. You can choose this ID by yourself to identify
your item later.</p>
        
        </div>
      </div>
      
      <div id="attribute-i-item_app_id" class="method-detail">
        <div class="method-heading attribute-method-heading">
          <span class="method-name">item_app_id</span><span
            class="attribute-access-type">[RW]</span>
        </div>

        <div class="method-description">
        
        <p>app id of an item</p>
        
        </div>
      </div>
      
      <div id="attribute-i-items" class="method-detail">
        <div class="method-heading attribute-method-heading">
          <span class="method-name">items</span><span
            class="attribute-access-type">[RW]</span>
        </div>

        <div class="method-description">
        
        <p>array containing instances of <a
href="BasketSetItem.html">AboutYou::SDK::Model::BasketSetItem</a></p>
        
        </div>
      </div>
      
      <div id="attribute-i-total_net" class="method-detail">
        <div class="method-heading attribute-method-heading">
          <span class="method-name">total_net</span><span
            class="attribute-access-type">[RW]</span>
        </div>

        <div class="method-description">
        
        <p>total net worth of the set</p>
        
        </div>
      </div>
      
      <div id="attribute-i-total_price" class="method-detail">
        <div class="method-heading attribute-method-heading">
          <span class="method-name">total_price</span><span
            class="attribute-access-type">[RW]</span>
        </div>

        <div class="method-description">
        
        <p>total price of the set</p>
        
        </div>
      </div>
      
      <div id="attribute-i-total_vat" class="method-detail">
        <div class="method-heading attribute-method-heading">
          <span class="method-name">total_vat</span><span
            class="attribute-access-type">[RW]</span>
        </div>

        <div class="method-description">
        
        <p>total vat worth of the set</p>
        
        </div>
      </div>
      
    </section>
    

    
     <section id="public-class-5Buntitled-5D-method-details" class="method-section">
       <header>
         <h3>Public Class Methods</h3>
       </header>

    
      <div id="method-c-new" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">new</span><span
            class="method-args">(id, additional_data = nil)</span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        

        <div class="method-description">
          
          <p>Constructor for the <a
href="BasketSet.html">AboutYou::SDK::Model::BasketSet</a> class</p>
<ul><li>
<p><strong>Args</strong>    :</p>
<ul><li>
<p><code>id</code> -&gt; the id of the basket set</p>
</li><li>
<p><code>additional_data</code> -&gt; additional data of the basket set</p>
</li></ul>
</li><li>
<p><strong>Returns</strong> :</p>
<ul><li>
<p>an instance of <a href="BasketSet.html">AboutYou::SDK::Model::BasketSet</a></p>
</li></ul>
</li></ul>
          
          

          
          <div class="method-source-code" id="new-source">
            <pre><span class="ruby-comment"># File lib/AboutYou/Model/Basket/basket_set.rb, line 46</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">id</span>, <span class="ruby-identifier">additional_data</span> = <span class="ruby-keyword">nil</span>)
  <span class="ruby-identifier">check_id</span>(<span class="ruby-identifier">id</span>)
  <span class="ruby-identifier">check_additional_data</span>(<span class="ruby-identifier">additional_data</span>, <span class="ruby-keyword">true</span>)
  <span class="ruby-keyword">self</span>.<span class="ruby-identifier">id</span> = <span class="ruby-identifier">id</span>
  <span class="ruby-keyword">self</span>.<span class="ruby-identifier">additional_data</span> = <span class="ruby-identifier">additional_data</span>

  <span class="ruby-keyword">self</span>
<span class="ruby-keyword">end</span></pre>
          </div>
          
        </div>

        

        
      </div>

    
    </section>
  
     <section id="public-instance-5Buntitled-5D-method-details" class="method-section">
       <header>
         <h3>Public Instance Methods</h3>
       </header>

    
      <div id="method-i-add_item" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">add_item</span><span
            class="method-args">(item)</span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        

        <div class="method-description">
          
          <p>This method is used for adding items to a basket set</p>
<ul><li>
<p><strong>Args</strong>    :</p>
<ul><li>
<p><code>item</code> -&gt; instance of <a
href="BasketSetItem.html">AboutYou::SDK::Model::BasketSetItem</a></p>
</li></ul>
</li><li>
<p><strong>Fails</strong> :</p>
<ul><li>
<p>if the app id of the set and item diverge</p>
</li></ul>
</li></ul>
          
          

          
          <div class="method-source-code" id="add_item-source">
            <pre><span class="ruby-comment"># File lib/AboutYou/Model/Basket/basket_set.rb, line 136</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">add_item</span>(<span class="ruby-identifier">item</span>)
  <span class="ruby-keyword">if</span> <span class="ruby-identifier">items</span>.<span class="ruby-identifier">count</span> <span class="ruby-operator">==</span> <span class="ruby-value">0</span>
    <span class="ruby-keyword">self</span>.<span class="ruby-identifier">item_app_id</span> = <span class="ruby-identifier">item</span>.<span class="ruby-identifier">app_id</span>
  <span class="ruby-keyword">elsif</span> <span class="ruby-identifier">item_app_id</span> <span class="ruby-operator">!=</span> <span class="ruby-identifier">item</span>.<span class="ruby-identifier">app_id</span>
    <span class="ruby-identifier">fail</span> <span class="ruby-string">'\InvalidArgumentException! you can not set different app ids
      for items in an item-set.'</span>
  <span class="ruby-keyword">end</span>

  <span class="ruby-identifier">items</span>.<span class="ruby-identifier">push</span>(<span class="ruby-identifier">item</span>)
<span class="ruby-keyword">end</span></pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-check_id" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">check_id</span><span
            class="method-args">(id)</span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        

        <div class="method-description">
          
          <p>This method is used for determining whether a certain id is valid for the
basket set or not</p>
<ul><li>
<p><strong>Args</strong>    :</p>
<ul><li>
<p><code>id</code> -&gt; the id which should be checked</p>
</li></ul>
</li><li>
<p><strong>Fails</strong> :</p>
<ul><li>
<p>if the id is not a String and its length is smaller then 2</p>
</li></ul>
</li></ul>
          
          

          
          <div class="method-source-code" id="check_id-source">
            <pre><span class="ruby-comment"># File lib/AboutYou/Model/Basket/basket_set.rb, line 189</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">check_id</span>(<span class="ruby-identifier">id</span>)
  <span class="ruby-identifier">fail</span> <span class="ruby-string">'\InvalidArgumentException! ID of the BasketSetItem must be a
    String that must contain minimum two characters'</span> <span class="ruby-keyword">unless</span>
      <span class="ruby-identifier">id</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">String</span>) <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">id</span>.<span class="ruby-identifier">length</span> <span class="ruby-operator">&gt;</span> <span class="ruby-value">1</span>
<span class="ruby-keyword">end</span></pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-create" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">create</span><span
            class="method-args">(item_id, sub_items, additional_data = nil)</span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        

        <div class="method-description">
          
          <p>This method is used for creating a basket set from an array containing
instances of <a
href="BasketSetItem.html">AboutYou::SDK::Model::BasketSetItem</a></p>
<ul><li>
<p><strong>Args</strong>    :</p>
<ul><li>
<p><code>item_id</code> -&gt; the id of the set</p>
</li><li>
<p><code>sub_items</code> -&gt; Array containing instances of <a
href="BasketSetItem.html">AboutYou::SDK::Model::BasketSetItem</a></p>
</li><li>
<p><code>additional_data</code> -&gt; additional data of the basket set</p>
</li></ul>
</li><li>
<p><strong>Returns</strong> :</p>
<ul><li>
<p>an instance of <a href="BasketSet.html">AboutYou::SDK::Model::BasketSet</a></p>
</li></ul>
</li></ul>
          
          

          
          <div class="method-source-code" id="create-source">
            <pre><span class="ruby-comment"># File lib/AboutYou/Model/Basket/basket_set.rb, line 112</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">create</span>(<span class="ruby-identifier">item_id</span>, <span class="ruby-identifier">sub_items</span>, <span class="ruby-identifier">additional_data</span> = <span class="ruby-keyword">nil</span>)
  <span class="ruby-identifier">set</span> = <span class="ruby-identifier">new</span>(<span class="ruby-identifier">item_id</span>, <span class="ruby-identifier">additional_data</span>)

  <span class="ruby-identifier">sub_items</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">item_data</span><span class="ruby-operator">|</span>
    <span class="ruby-identifier">set</span>.<span class="ruby-identifier">add_item</span>(
      <span class="ruby-constant">AboutYou</span><span class="ruby-operator">::</span><span class="ruby-constant">SDK</span><span class="ruby-operator">::</span><span class="ruby-constant">Model</span><span class="ruby-operator">::</span><span class="ruby-constant">BasketSetItem</span>.<span class="ruby-identifier">new</span>(
        <span class="ruby-identifier">item_data</span>[<span class="ruby-value">0</span>],
        <span class="ruby-identifier">item_data</span>[<span class="ruby-value">1</span>] <span class="ruby-operator">?</span> <span class="ruby-identifier">item_data</span>[<span class="ruby-value">1</span>] <span class="ruby-operator">:</span> <span class="ruby-keyword">nil</span>
      )
    )
  <span class="ruby-keyword">end</span>

  <span class="ruby-identifier">set</span>
<span class="ruby-keyword">end</span></pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-create_from_json" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">create_from_json</span><span
            class="method-args">(json_object, factory, products)</span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        

        <div class="method-description">
          
          <p>This method is used for creating a basket set with a given api json
response. It is best practice to use this method.</p>
<ul><li>
<p><strong>Args</strong>    :</p>
<ul><li>
<p><code>json_object</code> -&gt; the api response key</p>
</li><li>
<p><code>factory</code> -&gt; instance of <a
href="../Factory/DefaultModelFactory.html">AboutYou::SDK::Factory::DefaultModelFactory</a></p>
</li><li>
<p><code>products</code> -&gt; Array of products</p>
</li></ul>
</li><li>
<p><strong>Returns</strong> :</p>
<ul><li>
<p>an instance of <a href="BasketSet.html">AboutYou::SDK::Model::BasketSet</a></p>
</li></ul>
</li></ul>
          
          

          
          <div class="method-source-code" id="create_from_json-source">
            <pre><span class="ruby-comment"># File lib/AboutYou/Model/Basket/basket_set.rb, line 67</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">create_from_json</span>(<span class="ruby-identifier">json_object</span>, <span class="ruby-identifier">factory</span>, <span class="ruby-identifier">products</span>)
  <span class="ruby-identifier">set</span> = <span class="ruby-identifier">new</span>(
    <span class="ruby-identifier">json_object</span>[<span class="ruby-string">'id'</span>],
    <span class="ruby-keyword">if</span> <span class="ruby-identifier">json_object</span>.<span class="ruby-identifier">key?</span>(<span class="ruby-string">'additional_data'</span>)
      [<span class="ruby-identifier">json_object</span>[<span class="ruby-string">'additional_data'</span>]]
    <span class="ruby-keyword">else</span>
      <span class="ruby-keyword">nil</span>
    <span class="ruby-keyword">end</span>
    )

  <span class="ruby-identifier">set</span>.<span class="ruby-identifier">parse_error_result</span>(<span class="ruby-identifier">json_object</span>)

  <span class="ruby-identifier">json_object</span>[<span class="ruby-string">'set_items'</span>].<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">index</span>, <span class="ruby-identifier">json_term</span><span class="ruby-operator">|</span>
    <span class="ruby-identifier">item</span> = <span class="ruby-identifier">factory</span>.<span class="ruby-identifier">create_basket_set_item</span>(<span class="ruby-identifier">json_term</span>, <span class="ruby-identifier">products</span>)
    <span class="ruby-keyword">if</span> <span class="ruby-identifier">item</span>.<span class="ruby-identifier">errors?</span>
      <span class="ruby-identifier">set</span>.<span class="ruby-identifier">errors</span>[<span class="ruby-identifier">index</span>] = <span class="ruby-identifier">item</span>
    <span class="ruby-keyword">else</span>
      <span class="ruby-identifier">set</span>.<span class="ruby-identifier">items</span>[<span class="ruby-identifier">index</span>] = <span class="ruby-identifier">item</span>
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">if</span> <span class="ruby-identifier">json_object</span>.<span class="ruby-identifier">key?</span>(<span class="ruby-string">'total_price'</span>)
    <span class="ruby-identifier">set</span>.<span class="ruby-identifier">totalPrice</span> = <span class="ruby-identifier">json_object</span>[<span class="ruby-string">'total_price'</span>]
  <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">if</span> <span class="ruby-identifier">json_object</span>.<span class="ruby-identifier">key?</span>(<span class="ruby-string">'total_net'</span>)
    <span class="ruby-identifier">set</span>.<span class="ruby-identifier">totalPrice</span> = <span class="ruby-identifier">json_object</span>[<span class="ruby-string">'total_net'</span>]
  <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">if</span> <span class="ruby-identifier">json_object</span>.<span class="ruby-identifier">key?</span>(<span class="ruby-string">'total_vat'</span>)
    <span class="ruby-identifier">set</span>.<span class="ruby-identifier">totalPrice</span> = <span class="ruby-identifier">json_object</span>[<span class="ruby-string">'total_vat'</span>]
  <span class="ruby-keyword">end</span>

  <span class="ruby-identifier">set</span>
<span class="ruby-keyword">end</span></pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-errors-3F" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">errors?</span><span
            class="method-args">()</span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        

        <div class="method-description">
          
          <p>This method checks if there are errors in the basket set</p>
<ul><li>
<p><strong>Returns</strong> :</p>
<ul><li>
<p>Boolean determining whether there are errors or not</p>
</li></ul>
</li></ul>
          
          

          
          <div class="method-source-code" id="errors-3F-source">
            <pre><span class="ruby-comment"># File lib/AboutYou/Model/Basket/basket_set.rb, line 153</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">errors?</span>
  <span class="ruby-identifier">error_code</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">errors</span>.<span class="ruby-identifier">count</span> <span class="ruby-operator">&gt;</span> <span class="ruby-value">0</span>
<span class="ruby-keyword">end</span></pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-unique_key" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">unique_key</span><span
            class="method-args">()</span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        

        <div class="method-description">
          
          <p>This method is used for creating a unique key for the basket set</p>
<ul><li>
<p><strong>Returns</strong> :</p>
<ul><li>
<p>a String containing a unique key for the basket set</p>
</li></ul>
</li></ul>
          
          

          
          <div class="method-source-code" id="unique_key-source">
            <pre><span class="ruby-comment"># File lib/AboutYou/Model/Basket/basket_set.rb, line 163</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">unique_key</span>
  <span class="ruby-identifier">key</span> = <span class="ruby-string">':'</span>
  <span class="ruby-keyword">unless</span> <span class="ruby-identifier">additional_data</span>
    <span class="ruby-identifier">additional_data</span>.<span class="ruby-identifier">sort!</span>
    <span class="ruby-identifier">key</span> = <span class="ruby-identifier">key</span> <span class="ruby-operator">+</span> <span class="ruby-string">':'</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">additional_data</span>.<span class="ruby-identifier">to_json</span>
  <span class="ruby-keyword">end</span>

  <span class="ruby-identifier">items</span> = []
  <span class="ruby-keyword">self</span>.<span class="ruby-identifier">items</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">item</span><span class="ruby-operator">|</span>
    <span class="ruby-identifier">items</span>.<span class="ruby-identifier">push</span>(<span class="ruby-identifier">item</span>.<span class="ruby-identifier">unique_key</span>)
  <span class="ruby-keyword">end</span>
  <span class="ruby-identifier">key</span> <span class="ruby-operator">+=</span> <span class="ruby-identifier">items</span>.<span class="ruby-identifier">to_json</span>

  <span class="ruby-identifier">key</span>
<span class="ruby-keyword">end</span></pre>
          </div>
          
        </div>

        

        
      </div>

    
    </section>
  
  </section>
</main>


<footer id="validator-badges" role="contentinfo">
  <p><a href="http://validator.w3.org/check/referer">Validate</a>
  <p>Generated by <a href="http://rdoc.rubyforge.org">RDoc</a> 4.1.2.
  <p>Based on <a href="http://deveiate.org/projects/Darkfish-Rdoc/">Darkfish</a> by <a href="http://deveiate.org">Michael Granger</a>.
</footer>

